<template>
  <el-dialog v-model="dialogVisible" title="选择图标" center :width="dialogWidth" @close="handleDialogCancel()"
    destroy-on-close>
    <el-scrollbar height="400px">
      <div class="icon_container">
        <div class="icon_content" v-for="(item, index) in Object.keys(ElIcons)" :key="index" @click="iconHandle(item)">
          <el-icon :size="22">
            <component :is="item"></component>
          </el-icon>
          <div class="icon_font">{{ item }}</div>
        </div>
      </div>
    </el-scrollbar>


  </el-dialog>
</template>
<script lang="ts" setup>
import * as ElIcons from '@element-plus/icons-vue'
import { onMounted, reactive, ref, watch } from 'vue'
import { dialogAutoWidth } from '@/utils/dialog'
let dialogWidth = ref("30%")
// 生命周期
onMounted(() => {
  getWindowResize()
})
// 获取屏幕尺寸
const getWindowResize = function () {
  dialogWidth.value = dialogAutoWidth;
}
// 传值
const props = defineProps({
  dialogVisible: {
    type: Boolean,
    required: true,
    default: false,
  }
})
// 事件派发
const emits = defineEmits(["dialogClose", "getIcon"])
// 弹框中的取消按钮事件
const handleDialogCancel = () => {
  emits("dialogClose", false)
};

const iconHandle = (iconName: any) => {
  emits("getIcon", iconName)
  handleDialogCancel();
}

</script>
<style scoped>
.icon_container {
  display: flex;
  flex-wrap: wrap;
}

.icon_content {
  cursor: pointer;
  height: 50px;
  width: 92px;
  border: 1px solid #dcdfe6;
  ;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.icon_content:hover {
  background-color: #f2f6fb;
}

.icon_font {
  font-size: 3px;
  margin-top: 5px;
}

.el-icon {
  margin-right: 0px;
}
</style>